<template>
  <div>
    <el-card class="box-card" style="margin-left: 100px;margin-right: 100px;">
      <el-form ref="elForm" :model="formData" :rules="rules" size="small" label-width="100px">
        <el-form-item label="运单号" prop="waybillNo">
          <el-input v-model="formData.waybillNo" placeholder="请输入运单号" clearable :style="{width: '100%'}" :disabled = "waybillNoDisabled"></el-input>
        </el-form-item>
        <el-form-item label="实重" prop="inStockActualWeight">
          <el-input v-model="formData.inStockActualWeight" placeholder="请输入实重" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="体积" prop="inStockVolume">
          <el-input v-model="formData.inStockVolume" placeholder="请输入体积" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="件数" prop="inStockTotalPackages">
          <el-input v-model="formData.inStockTotalPackages" placeholder="请输入件数" clearable
                    :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="仓库" prop="storageLocation">
          <el-select v-model="formData.storageLocation" placeholder="请选择仓库" clearable :style="{width: '100%'}">
            <el-option v-for="item in storageLocationOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item size="small">
          <el-button type="primary" @click="submitForm" v-loading.fullscreen.lock="fullscreenLoading">快速入库</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
  import { ajax } from "@/store/yg/common/utils";
  import { m } from "@/store/yg/common/local";
  export default {
    components: {},
    props: [],
    data() {
      return {
        fullscreenLoading: false,
        id: null,
        waybillNoDisabled: false,
        formData: {
          waybillNo: null,
          inStockActualWeight: null,
          inStockVolume: null,
          inStockTotalPackages: null,
          storageLocation: null,
        },
        rules: {
          waybillNo: [{
            required: true,
            message: '请输入运单号',
            trigger: 'blur'
          }],
          inStockActualWeight: [{
            required: true,
            message: '请输入实重',
            trigger: 'blur'
          }],
          inStockVolume: [{
            required: true,
            message: '请输入体积',
            trigger: 'blur'
          }],
          inStockTotalPackages: [{
            required: true,
            message: '请输入件数',
            trigger: 'blur'
          }],
          storageLocation: [{
            required: true,
            message: '请选择仓库',
            trigger: 'change'
          }],
        },
        storageLocationOptions: [],
      }
    },
    created() {},
    mounted() {
      this.storageLocations();
      if (this.$route.query.pid) {
        // console.log(this.$route.query.pid);
        ajax("findSeaairwaybillInstockById", {'id':this.$route.query.pid}).then(
          res => {
            console.log(res);
            this.waybillNoDisabled = true;
            this.id = res.id;
            this.formData.waybillNo = res.waybillNo;
            this.formData.inStockActualWeight = res.inStockActualWeight;
            this.formData.inStockVolume = res.inStockVolume;
            this.formData.inStockTotalPackages = res.inStockTotalPackages;
            this.formData.storageLocation = res.storageLocation;
          },
          error => {
            console.log(error);
          }
        )
      }
    },
    methods: {
      storageLocations: function() {
        ajax("storageLocations", {}).then(
          res => {
            console.log(res);
            if (res.code == 200) {
              this.storageLocationOptions = res.data2;
              this.storageLocation = res.data;
            } else {
              this.$message.error("操作失败，" + res.message);
            }
          },
          error => {
            console.log(error);
          }
        );
      },
      submitForm() {
        this.$refs['elForm'].validate(valid => {
          if (!valid) return
          console.log(this.formData);
          this.saveFastInstock(this.formData);
        })
      },
      async saveFastInstock(params) {
        this.fullscreenLoading = true;
        var url = "saveFastInstockInfo";
        console.log('id=='+this.id)
        if(this.id){
          url = "updateastInstockInfo";
        }
        const data = await ajax(url, params);
        this.fullscreenLoading = false;
        if (data.code == 200) {
          this.$message.success('保存成功');
        }else{
          this.$message.error(m(data.message));
        }
      }
    }
  }

</script>
<style>
</style>
